export const CELLPHONE_REG = /^1[3-9]\d{9}$/;

export function verifyByToast(value,rules){
	let title;
	for(let i=0;i<rules.length;i++){
		const rule = rules[i];
		if((rule.required && !value) 
			|| (rule.reg && !rule.reg.test(value))
		){
			title = rule.message;
			break;
		}
	}
	if(title){
		uni.showToast({
			icon: "error",
			title
		});
		return false;
	}
	return true;
}

export function getVerifyMessage(value,rules){
	let message;
	for(let i=0;i<rules.length;i++){
		const rule = rules[i];
		if((rule.required && !value) 
			|| (rule.reg && !rule.reg.test(value))
		){
			message = rule.message;
			break;
		}
	}
	return message || null;
}

export function verifyCellphone(value){
	return getVerifyMessage(value,[{
		required: true,
		message: "请输入手机号码"
	},{
		reg: CELLPHONE_REG,
		message: "请输入正确的11位手机号码"
	}]);
}